******************
* Analysis Do File for Beyond Zeros and Ones
*****************
clear all
set mem 800m
set more off
set matsize 800

cd "C:\Dropbox\CivilWar\Civil War Replication\"
use working_2014_06_30.dta, clear

***
*Figure 1: Distribution of Log Battle Deaths in Conflict Years
***
gen logdead = log(bdeadbes_3_av)
hist logdead if bdeadbes_3_av!=0, kdens xtitle("log(Deaths)") graphr(fcolor(white)) start(2)
	graph export "fig1_logbd.eps", as(eps) preview(off) replace

***
*Figure 2: Log Battle Deaths in Year t Versus Log Deaths in Year t-1
***
reg logAv lagLogAv
twoway (lowess logAv lagLogAv) (lfit logAv lagLogAv) (scatter logAv lagLogAv), legend(label(1 "Locally Weighted Semi-Parametric Estimate") label(2 "Linear Fit, Slope 0.81") label(3 "Actual Data")) ytitle("Log Battle Deaths at t") legend(cols(1))  graphr(fcolor(white))
	graph export "fig2_tt1.eps", as(eps) preview(off) replace

label var lagLogNoAv "Log Battle Deaths at t-1"
label var logNoAv "Log Battle Deaths at t"

***
*Appendix Figure 1: Non-Interpolated Log Battle Deaths in Year t Versus Log Deaths in Year t-1
***
reg logNoAv lagLogNoAv
twoway (lowess logNoAv lagLogNoAv) (lfit logNoAv lagLogNoAv) (scatter logNoAv lagLogNoAv), legend(label(1 "Locally Weighted Semi-Parametric Estimate") label(2 "Linear Fit, Slope 0.86") label(3 "Actual Data")) ytitle("Log Battle Deaths at t") legend(cols(1))  graphr(fcolor(white))
	graph export "appfig1.eps", as(eps) preview(off) replace


* Summary info for mean conflict spells
* Mean conflict spell length, 198 conflict spells, lasting an average of 5.09 years.
preserve
duplicates drop ccode _spell, force
drop if _spell==0
su conflictlength
restore

gen escalkeep = 0
replace escalkeep = 1 if conflictyear>=1
replace escalkeep = 1 if conflictyear==0 & l.conflictyear>=1

* The probability of escalation, assuming that this isn't the first year of conflict, is:
su escal if escalkeep==1 & conflictyear!=1

* Differenced GDP variables for first stage
xtset ccode year
gen dy_it = d.y_it
gen dyhat_log = d.yhat_log
gen ldbdeadbes_3_av = l.d.bdeadbes_3_av
gen ldwarFromBDead = l.d.warFrom


tempfile firstD
save "`firstD'"
keep if e(sample) 
keep if ldbdeadbes_3_av<.


mata 
Z=st_data(., "dyhat_log YR*")
X=st_data(., "dy_it YR*")
Y=st_data(., "ldbdeadbes_3_av")
qrinv(Z'*X)*Z'*Y


end
clear
use "`firstD'"

ivreg d.warFrom (dy_it = dyhat_log) YR*, robust
tempfile firstD
save "`firstD'"
keep if e(sample) 
keep if ldwarFromBDead<.
ivreg d.warFrom (dy_it = dyhat_log) YR*, robust

mata 
Z=st_data(., "dyhat_log YR*")
X=st_data(., "dy_it YR*")
Y=st_data(., "ldwarFromBDead")
qrinv(Z'*X)*Z'*Y
end

clear
use "`firstD'"

saveold working.dta, replace


***
* Table 1: Summary Statistics
***

cd "C:\Dropbox\CivilWar\Civil War Replication\"
use working.dta, clear

*Summary Stats, battledeaths, war, warfrombdead, log(PCGDP), log(PCGDP) yes dead, log(PCGDP) no dead
gen y_it_dead = .
replace y_it_dead = y_it if warFromBDead==1
gen y_it_nodead = .
replace y_it_nodead = y_it if warFromBDead==0

bysort ccode: egen LM_dynamic = min(lmtnest)
bysort ccode: egen Oil_dynamic = mean(Oil)
replace Oil_dynamic = 1 if Oil_dynamic>0 & Oil_dynamic<.

bysort ccode: egen Rel_dynamic = mean(relfrac)
bysort ccode: egen Eth_dynamic = mean(ethfrac)

gen lmInter = l.bdeadbes_3_av*LM_dynamic
gen oilInter = l.bdeadbes_3_av*Oil_dynamic



sum LM_dynamic, d
gen LM_sample = LM_dynamic>=r(p50)
replace LM_sample = . if LM_dynamic==.
sum Rel_dynamic, d
gen Rel_sample = Rel_dynamic >= r(p50)
replace Rel_sample=. if Rel_dynamic==.
sum Eth_dynamic, d
gen Eth_sample = Eth_dynamic >= r(p50)
replace Eth_sample=. if Eth_dynamic==.

gen Oil_sample = Oil_dynamic==1

foreach i of varlist LM_sample Rel_sample Eth_sample Oil_sample {
	replace `i' = 0 if region2==0
}


*************
* Table 1 Construction
*************

*Defining Main Estimation Sample for Creation of Summary Stats Table
xtset ccode year
xtabond2 bdeadbes_3_av y_it l.bdeadbes_3_av YR*,  gmm(bdeadbes_3_av, laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
gen mainEstSample = e(sample)




*************
* Table 1 Output
*************
sum bdeadbes_3_av warFrom y_it if mainEstSample
sum bdeadbes_3_av warFrom y_it if mainEstSample & region2==6
sum bdeadbes_3_av warFrom y_it if mainEstSample & region2!=0
sum bdeadbes_3_av warFrom y_it if mainEstSample & region2!=6
sum bdeadbes_3_av warFrom y_it if mainEstSample & Eth_sample
sum bdeadbes_3_av warFrom y_it if mainEstSample & Rel_sample
sum bdeadbes_3_av warFrom y_it if mainEstSample & LM_sample
sum bdeadbes_3_av warFrom y_it if mainEstSample & Oil_sample


***
* Table 2: First Stage in first differences, with sequence instrument
***


*Table 2 Panel A
* Main first stage table- sequence instrument- with robust- without cluster, with fixed effects
 reg d.y_it d.yhat_log d.YR*, robust
outreg2 using firstStage, excel replace addstat(F Stat, `e(F)')  ctitle(All)
 reg d.y_it d.yhat_log d.YR* if region2==6, robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(SSA)
 reg d.y_it d.yhat_log d.YR* if region2!=0, robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(NonWestDem)
 reg d.y_it d.yhat_log d.YR* if region2~=6, robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(No SSA)


*Table 2 Panel B
* Main first stage table- sequence instrument- with robust- without cluster, with fixed effects, with country-specific time trends
 reg d.y_it d.yhat_log d.YR* d.CSTT*, robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)')  ctitle(All CSTT)
 reg d.y_it d.yhat_log d.YR* d.CSTT* if region2==6 , robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(SSA)
 reg d.y_it d.yhat_log d.YR* d.CSTT* if region2!=0 , robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(NonWestDem)
 reg d.y_it d.yhat_log d.YR* d.CSTT* if region2~=6 , robust
outreg2 using firstStage, excel addstat(F Stat, `e(F)') ctitle(No SSA)





***
* XTABOND (Tables 3 and 5)
***

gen warF_x_confY = warFromB*conflictyear
*** Tables 3 and 5
foreach i in bdeadbes_3_av warF_x_confY {

*Table 3 Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_av using T3ab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)


*Table 5 Panel A/B
xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if Eth_sample, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5ab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Eth_sample)

xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if Rel_sample, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Rel_sample)

xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if LM_sample, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(LM_sample)

xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if Oil_sample, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Oil_sample)



*Table 3 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_av using T3cd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)


*Table 5 Panel C/D
xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if Eth_sample, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5cd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(`j')

foreach j in Rel_sample LM_sample Oil_sample {
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if `j', gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T5cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(`j')
}

}


 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* if e(sample),  gmm(bdeadbes_3_noav, laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 

set more off



***Appendix Table 4 (Equivalent to Table 3 Excluding Interpolated Battle Deaths)
foreach i in bdeadbes_3_noav warF_x_confY {

*Appendix Table 1  Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_noav using AppT1ab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 sum bdeadbes_3_noav bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_noav using AppT1ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 sum bdeadbes_3_noav bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* if region2~=0,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_noav using AppT1ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 sum bdeadbes_3_noav bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_noav using AppT1ab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

*Appendix Table 1 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D
 sum bdeadbes_3_noav bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* CSTT*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_noav using AppT1cd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* CSTT* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_noav using AppT1cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* CSTT* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_noav using AppT1cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadbes_3_noav y_it lbdeadbes_3_noav YR* CSTT* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_noav using AppT1cd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

}
*




***
* Appendix Table 2 (Equivalent to Table 3 with "Low" Battle Deaths Series and Additional Subsamples)
***
capture drop lbdead_low_3
gen lbdeadlow_3 = l.bdeadlow_3
gen warF_x_confY = warFromB*conflictyear

foreach i in bdeadlow_3 warF_x_confY {

*Appendix Table 2 Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B

 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadlow_3 using T3_Lowab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

foreach j in Eth_sample Rel_sample LM_sample Oil_sample {
	xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* if `j', gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
	outreg2 y_it lbdeadlow_3 using T3_Lowab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(`j')
}	

*Appendix Table 2 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D

 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* CSTT*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadlow_3 using T3_Lowcd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* CSTT* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* CSTT* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* CSTT* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadlow_3 using T3_Lowcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

foreach j in Eth_sample Rel_sample LM_sample Oil_sample {
	xtabond2 bdeadlow_3 y_it lbdeadlow_3 YR* CSTT* if `j', gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
	outreg2 y_it lbdeadlow_3 using T3_Lowcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(`j')
}

}
*


***
* Table 6
* GMM Models with binary indicator variables, instead of bdead
***

* Panel A
 xtabond2 warFromBDead y_it lwarFromBDead YR*,  gmm(l.warFromBDead, laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal artests(4)
outreg2 y_it lwarFromBDead using T4_warFrom, excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  
 xtabond2 warFromBDead y_it lwarFromBDead YR* if region2==6, gmm(l.warFromBDead, laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal artests(4)
outreg2 y_it lwarFromBDead using T4_warFrom, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  
xtabond2 warFromBDead y_it lwarFromBDead YR* if region2==6, gmm(l.warFromBDead, laglimits(3 5)) iv(GPCP YR*) nodiffsargan robust orthogonal artests(4)
outreg2 y_it lwarFromBDead using T4_warFrom, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')   
 xtabond2 warFromBDead y_it lwarFromBDead YR* if region2~=0, gmm(l.warFromBDead, laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal artests(4)
outreg2 y_it lwarFromBDead using T4_warFrom, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  
 xtabond2 warFromBDead y_it lwarFromBDead YR* if region2~=6, gmm(l.warFromBDead, laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal artests(4)
outreg2 y_it lwarFromBDead using T4_warFrom, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  

* Panel B
 xtabond2 war y_it lwar YR*,  gmm(l.war, laglimits(2 4)) iv(yhat_log YR*) robust nodiffsargan orthogonal
outreg2 y_it lwar using T4_war, excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 war y_it lwar YR* if region2==6, gmm(l.war, laglimits(2 4)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lwar using T4_war, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  
 xtabond2 war y_it lwar YR* if region2==6, gmm(l.war, laglimits(2 4)) iv(GPCP YR*) nodiffsargan robust orthogonal
outreg2 y_it lwar using T4_war, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  
 xtabond2 war y_it lwar YR* if region2~=0, gmm(l.war, laglimits(2 4)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lwar using T4_war, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  
 xtabond2 war y_it lwar YR* if region2~=6, gmm(l.war, laglimits(2 4)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lwar using T4_war, excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  





***
*Table 4
* Dynamics Regressions
***

capture drop lbdeadlow_3
gen lbdeadlow_3 = l.bdeadlow_3



capture program drop runDynamics
program define runDynamics

	xtabond2 `1' ly_it l`1' YR* `5' `6', gmm(`1', laglimits(3 5)) iv(lyhat_log YR* `5') robust nodiffsargan artest(4) orthogonal
	outreg2 ly_it l`1' using Dyn_`4', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  ctitle(`1')

	xtabond2 `1' ly_it l`1' `2' YR* `5' `6', gmm(`1', laglimits(3 5)) gmm(`3', laglimits(0 0) collapse)  iv(lyhat_log YR* `5') robust nodiffsargan artest(4) orthogonal
	capture drop spillOver
	gen spillOver = (_b[l`1']*l`1'+_b[`2']*`2')/l`1'
	sum spillOver, d
	local p5 = r(p5)
	local p10 = r(p10)
	local p50 = r(p50)
	local p90 = r(p90)
	local p95 = r(p95)
	local MS = r(mean)
	local Mdev = r(sd)
	outreg2 ly_it l`1' `2' using Dyn_`4', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)', p5, `p5', p10, `p10', p50, `p50', p90, `p90', p95, `p95', MS, `MS', Mdev, `Mdev')  ctitle(`1')


	xtabond2 `1' ly_it l`1' YR* `5' `6', gmm(warF_, laglimits(3 5)) iv(lyhat_log YR* `5') robust nodiffsargan artest(4) orthogonal
	outreg2 ly_it l`1' using Dyn_`4', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)')  ctitle(`1')

	xtabond2 `1' ly_it l`1' `2' YR* `5' `6', gmm(warF_, laglimits(3 5)) gmm(`3', laglimits(0 0) collapse)  iv(lyhat_log YR* `5') robust nodiffsargan artest(4) orthogonal
	capture drop spillOver
	gen spillOver = (_b[l`1']*l`1'+_b[`2']*`2')/l`1'
	sum spillOver, d
	local p5 = r(p5)
	local p10 = r(p10)
	local p50 = r(p50)
	local p90 = r(p90)
	local p95 = r(p95)
	local MS = r(mean)
	local Mdev = r(sd)
	outreg2 ly_it l`1' `2' using Dyn_`4', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', AB Test of AR 3 p-value, `e(ar3p)', Number of Instruments, `e(j)', p5, `p5', p10, `p10', p50, `p50', p90, `p90', p95, `p95', MS, `MS', Mdev, `Mdev')  ctitle(`1' warF)


end


gen deadInter = l.bdeadbes_3_av*l.y_it


capture drop lbdeadlow_3
gen lbdeadlow_3 = l.bdeadlow_3

gen Int_warF = warF_*l.yhat_log

runDynamics bdeadbes_3_av deadInter Int_warF 3AvBin "" ""







***
* Appendix Table 1 (Equivalent to Table 3 with "High" Battle Deaths Series and Additional Subsamples)
***
cd "C:\Dropbox\CivilWar\Civil War Replication\"
use working_2014_06_30.dta, clear
capture drop lbdead_hig_3
gen lbdeadhig_3 = l.bdeadhig_3
gen warF_x_confY = warFromB*conflictyear


foreach i in bdeadhig_3 warF_x_confY {

*Appendix Table 2 Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B

 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadhig_3 using T3_Highab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)



*Appendix Table 2 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D

 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* CSTT*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadhig_3 using T3_Highcd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* CSTT* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* CSTT* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadhig_3 y_it lbdeadhig_3 YR* CSTT* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadhig_3 using T3_Highcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

}
*

***
* Appendix Table 3 (Equivalent to Table 3 with Categorical DV)
***
gen categintens = .
replace categintens = 0 if bdeadbes_3_av !=. & bdeadbes_3_av <=24
replace categintens = 1 if bdeadbes_3_av >=25 & bdeadbes_3_av <=999
replace categintens = 2 if bdeadbes_3_av >=999 & bdeadbes_3_av !=.

gen lcategintens = l.categintens


foreach i in categintens warF_x_confY {

*Appendix Table 2 Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B

 xtabond2 categintens y_it lcategintens YR*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lcategintens using T3_Categab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 categintens y_it lcategintens YR* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 categintens y_it lcategintens YR* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 categintens y_it lcategintens YR* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)



*Appendix Table 2 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D

 xtabond2 categintens y_it lcategintens YR* CSTT*,  gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lcategintens using T3_Categcd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 categintens y_it lcategintens YR* CSTT* if region2==6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 categintens y_it lcategintens YR* CSTT* if region2~=0, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 categintens y_it lcategintens YR* CSTT* if region2~=6, gmm(`i', laglimits(3 5)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lcategintens using T3_Categcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

}
*

***
* Appendix Table 5
* First stages for the lag instruments
***

use working_2014_06_30.dta, clear
xtset ccode year
xtabond2 bdeadbes_3_av y_it l.bdeadbes_3_av YR*,  gmm(bdeadbes_3_av, laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
gen mainEstSample = e(sample)

gen warF_x_confY = warFromB*conflictyear

forvalues i = 1/7 {
	gen l`i'_bdeadbes_3_av = l`i'.bdeadbes_3_av
	gen ld`i'_bdeadbes_3_av = l`i'.d.bdeadbes_3_av
	gen l`i'_warF_x_confY = l`i'.warF_x_confY
	gen ld`i'_warF_x_confY = l`i'.d.warF_x_confY
}
gen d_bdeadbes_3_av = d.bdeadbes_3_av



forvalues i = 3/5 {
	gen I_`i' = l`i'.bdeadbes_3_av
	gen MI_`i' = I_`i'==.
	replace I_`i' = 0 if I_`i'==.
	gen IW_`i' = l`i'.warF_x_confY
	gen MIW_`i' = IW_`i'==.
	replace IW_`i' = 0 if IW_`i'==.
}
*

** First differences
	* Panel A, Column 1
areg ld1_bdeadbes_3_av I_3 l.d.yhat_log if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(FD) addstat(F, e(F))
	* Panel A, Column 2
areg ld1_bdeadbes_3_av I_3 I_4 I_5 l.d.yhat_log if mainEstSample , robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(FD) addstat(F, e(F))
	* Panel A, Column 3
areg ld1_bdeadbes_3_av I_3 l.d.yhat_log YR* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(FD FE) addstat(F, e(F))
	* Panel A, Column 4
areg ld1_bdeadbes_3_av I_3 I_4 I_5 l.d.yhat_log YR* if mainEstSample , robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(FD FE) addstat(F, e(F))
	* Panel A, Columns 5-8
areg ld1_bdeadbes_3_av IW_3 l.d.yhat_log if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(FD) addstat(F, e(F))
areg ld1_bdeadbes_3_av IW_3 l.d.yhat_log YR* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(FD FE) addstat(F, e(F))
areg ld1_bdeadbes_3_av IW_3 IW_4 IW_5 l.d.yhat_log if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(FD) addstat(F, e(F))
areg ld1_bdeadbes_3_av IW_3 IW_4 IW_5 l.d.yhat_log YR* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(FD FE) addstat(F, e(F))

* Panel B
forvalues i = 2/4 {
	gen isM_`i' = ld`i'_bdeadbes_3_av==.
	replace ld`i'_bdeadbes_3_av = 0 if ld`i'_bdeadbes_3_av==.
	
}
replace ld2_warF_x_conf = 0 if ld2_warF_x_conf==.
** Levels
areg l.bdeadbes_3_av ld2_bdeadbes_3_av yhat_log if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(Levels) addstat(F, e(F))

areg l.bdeadbes_3_av ld2_bdeadbes_3_av yhat_log CSTT* if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(Levels CSTT) addstat(F, e(F))

areg l.bdeadbes_3_av ld2_bdeadbes_3_av yhat_log YR* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(Levels FE) addstat(F, e(F))

areg l.bdeadbes_3_av ld2_bdeadbes_3_av yhat_log YR* CSTT* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(Levels FE CSTT) addstat(F, e(F))


test ld2_bdeadbes_3_av

areg l.bdeadbes_3_av ld2_warF_x_conf yhat_log  if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(Levels) addstat(F, e(F))

test ld2_warF_x_conf yhat_log

areg l.bdeadbes_3_av ld2_warF_x_conf yhat_log CSTT* if mainEstSample, robust absorb(year)
outreg2 using firstStage_GMM, excel ctitle(Levels CSTT) addstat(F, e(F))

areg l.bdeadbes_3_av ld2_warF_x_conf yhat_log YR* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(Levels FE) addstat(F, e(F))

areg l.bdeadbes_3_av ld2_warF_x_conf yhat_log YR* CSTT* if mainEstSample, robust absorb(ccode)
outreg2 using firstStage_GMM, excel ctitle(Levels FE CSTT) addstat(F, e(F))



***
* Appendix Table 6
* GMM Models, with restricted instruments, no collapse
***

*** 3 3, NO COLLAPSE
capture gen warF_x_confY = warFromB*conflictyear
*** Tables 3-- redone for the appendix
foreach i in bdeadbes_3_av warF_x_confY {

*Table 3 Panel A/B
*First iteration of loop creates Panel A
*Second iteration of loop creates Panel B
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR*,  gmm(`i', laglimits(3 3)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_av using T3AppNoColab_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2==6, gmm(`i', laglimits(3 3)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2~=0, gmm(`i', laglimits(3 3)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* if region2~=6, gmm(`i', laglimits(3 3)) iv(yhat_log YR*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColab_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)


*Table 3 Panel C/D
*First iteration of loop creates Panel C
*Second iteration of loop creates Panel D
 sum bdeadbes_3_av bdeadbes_3_noav warFromBDead y_it if e(sample)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT*,  gmm(`i', laglimits(3 3)) iv(yhat_log YR* CSTT*) robust nodiffsargan orthogonal 
outreg2 y_it lbdeadbes_3_av using T3AppNoColcd_IV`i', excel replace addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(All)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2==6, gmm(`i', laglimits(3 3)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Sub-Saharan Africa)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2~=0, gmm(`i', laglimits(3 3)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Western Democracies)
 xtabond2 bdeadbes_3_av y_it lbdeadbes_3_av YR* CSTT* if region2~=6, gmm(`i', laglimits(3 3)) iv(yhat_log YR* CSTT*) nodiffsargan robust orthogonal
outreg2 y_it lbdeadbes_3_av using T3AppNoColcd_IV`i', excel addstat(Overidentifying Restrictions p-value, `e(hansenp)', AB Test of AR 1 p-value, `e(ar1p)', AB Test of AR 2 p-value, `e(ar2p)', Number of Instruments, `e(j)')  ctitle(Excluding Sub-Saharan Africa)

}
*



***
* Appendix Table 7
* Linear models with and without FE
***
capture xtset ccode year
xtabond2 bdeadbes_3_av y_it l.bdeadbes_3_av YR*,  gmm(bdeadbes_3_av, laglimits(3 5)) iv(yhat_log YR*) robust nodiffsargan orthogonal 
capture gen mainEstSample = e(sample)
*Linear Models, Levels, No Instruments, no Country FE
reg bdeadbes_3_av y_it  YR* if mainEstSample, robust cluster(ccode)
	outreg2 using linmodnofe, excel replace
reg bdeadbes_3_av y_it  YR* if region2==6 & mainEstSample, robust cluster(ccode)
	outreg2 using linmodnofe, excel ctitle(SSA)
reg bdeadbes_3_av y_it  YR* if region2~=0 & mainEstSample, robust cluster(ccode)
	outreg2 using linmodnofe, excel ctitle(noWD)
reg bdeadbes_3_av y_it  YR* if region2~=6 & mainEstSample, robust cluster(ccode)
	outreg2 using linmodnofe, excel ctitle(noSSA)
*Linear Models, Levels, No Instruments, yes Country FE
xtreg bdeadbes_3_av y_it  YR* if mainEstSample, fe robust
	outreg2 using linmodyesfe, excel replace
xtreg bdeadbes_3_av y_it  YR* if region2==6 & mainEstSample, fe robust
	outreg2 using linmodyesfe, excel ctitle(SSA)
xtreg bdeadbes_3_av y_it  YR* if region2~=0 & mainEstSample, fe robust
	outreg2 using linmodyesfe, excel ctitle(noWD)
xtreg bdeadbes_3_av y_it  YR* if region2~=6 & mainEstSample, fe robust
	outreg2 using linmodyesfe, excel ctitle(noSSA)
*Linear Models, First Differences, No Instruments, no Country FE
reg dbdeadbes_3_av dy_it  YR* if mainEstSample, robust cluster(ccode)
	outreg2 using linnofediff, excel replace 
reg dbdeadbes_3_av dy_it  YR* if region2==6 & mainEstSample, robust cluster(ccode)
	outreg2 using linnofediff, excel ctitle(SSA)
reg dbdeadbes_3_av dy_it  YR* if region2~=0 & mainEstSample, robust cluster(ccode)
	outreg2 using linnofediff, excel ctitle(noWD)
reg dbdeadbes_3_av dy_it  YR* if region2~=6 & mainEstSample, robust
	outreg2 using linnofediff, excel ctitle(noSSA)
*Linear Models, First Differences, No Instruments, yes Country FE
xtreg dbdeadbes_3_av dy_it  YR* if mainEstSample, fe robust
	outreg2 using linyesfediff, excel replace
xtreg dbdeadbes_3_av dy_it  YR* if region2==6 & mainEstSample, fe robust
	outreg2 using linyesfediff, excel ctitle(SSA)
xtreg dbdeadbes_3_av dy_it  YR* if region2~=0 & mainEstSample, fe robust
	outreg2 using linyesfediff, excel ctitle(noWD)
xtreg dbdeadbes_3_av dy_it  YR* if region2~=6 & mainEstSample, fe robust
	outreg2 using linyesfediff, excel ctitle(noSSA)


***
* Appendix Table 8
* Models without residuals outliers
***

reg dbdeadbes_3_av dy_it  YR*, robust cluster(ccode)
	predict res_norestric, residuals
	outreg2 using linnofediff_res, excel replace 
	kdensity res_norestric if e(sample), xtitle("Residuals from Linear First Differences")
	graph export res_fd_RR_norestrict.eps, replace

reg dbdeadbes_3_av dy_it  YR* if abs(res_norestric)<50000, robust cluster(ccode)
	predict res_50k, residuals
	outreg2 using linnofediff_res, excel ctitle(Rest50k) 
	kdensity res_50k if e(sample), xtitle("Residuals from 50k sample")
	graph export res_fd_RR_50k.eps, replace

reg dbdeadbes_3_av dy_it  YR* if abs(res_norestric)<15000, robust cluster(ccode)
	predict res_15k, residuals
	outreg2 using linnofediff_res, excel ctitle(Rest15k)
	kdensity res_15k if e(sample), xtitle("Residuals from 15k sample")
	graph export res_fd_RR_15k.eps, replace

* Sensitivity with country fixed effects
areg dbdeadbes_3_av dy_it YR*, absorb(ccode)
	predict res_fefd_norest, residuals
	kdensity res_fefd_norest if e(sample), xtitle("Residuals from First Differences with Fixed Effects")
	graph export res_fefd_RR_norestrict.eps, replace
xtreg dbdeadbes_3_av dy_it  YR* if abs(res_fefd_norest)<50000, fe robust
	outreg2 using linyesfediff_res, excel replace 
xtreg dbdeadbes_3_av dy_it  YR* if abs(res_fefd_norest)<15000, fe robust
	outreg2 using linyesfediff_res, excel ctitle(restrict15k)
xtreg dbdeadbes_3_av dy_it  YR* if abs(res_fefd_norest)<15000 & region2==6, fe robust
	outreg2 using linyesfediff_res, excel ctitle(restrictSSA15k)	
xtreg dbdeadbes_3_av dy_it  YR* if abs(res_fefd_norest)<15000 & region2!=0, fe robust
	outreg2 using linyesfediff_res, excel ctitle(restrictNoWD15k)	
xtreg dbdeadbes_3_av dy_it  YR* if abs(res_fefd_norest)<15000 & region2!=6, fe robust
	outreg2 using linyesfediff_res, excel ctitle(restrictNoSSA15k)	
